<template>
	<view class="wrap bgw">
		<view class="header p30">
			<view class="user p30">
				<image class="userimg" :src="user.avatarImg"></image>
				<view class="txw cw">
					<p class="p1 one text-xl"> {{ user.username }}</p>
					<p class="p2 one text-df">{{ user.mobile }}</p>
				</view>
				<view class="state b text-xs">{{ txt }}</view>
				<view @tap="GoOpenVip()" v-if="serve.status == 1" class="lable">
					<image class="fl" src="../../static/image/opensshangjia.png" mode=""></image>
					<view class="fl text-sm">
						<p>点击续费</p>
						<p>{{ endTime }}</p>
					</view>
				</view>
			</view>
		</view>
		<view class="nav ">
			<h3 class="p30">常用工具</h3>
			<ul class="text-df ">
				<li @tap="Go(0)">
					<image src="../../static/image/navs1.png" mode=""></image>
					<br/> 商家认证
				</li>
				<li @tap="Go(1)">
					<image src="../../static/image/navs2.png" mode=""></image>
					<br/> 开办会员卡
				</li>
				<li @tap="Go(2)">
					<image src="../../static/image/navs4.png" mode=""></image>
					<br/> 充值会员卡
				</li>
				<li @tap="Go(3)">
					<image src="../../static/image/huiyuanka.png" mode=""></image>
					<br/> 会员卡收款
				</li>
				<li @tap="Go(4)">
					<image src="../../static/image/navs5.png" mode=""></image>
					<br/> 剧豆收款
				</li>
				<li @tap="Go(6)">
					<image src="../../static/image/1222.png" mode=""></image>
					<br/> 营销管理
				</li>
				<li @tap="Go(7)">
					<image src="../../static/image/1221.png" mode=""></image>
					<br/> 优惠券折扣
				</li>
			</ul>
		</view>
		<view class="nav nav2  ">
			<h3 class="p30">其他工具</h3>
			<ul class="text-df ">
				<li @tap="Go(8)">
					<image src="../../static/image/NewsIndex.png" mode=""></image>
					<br/> 公告管理
				</li>
				<li @tap="Go(5)">
					<image src="../../static/image/memberIndex.png" mode=""></image>
					<br/> 我的会员
				</li>
				<li @tap="GoHelp()">
					<image src="../../static/image/gonggaoIndex.png" mode=""></image>
					<br/> 使用帮助
				</li>
			</ul>
		</view>
	</view>
</template>

<script>
	import {
		myInfo,
		storeinfo,
		getServiceStatus,
		useCoupon,
		getEndDate
	} from '@/api/api.js';
	import {
		Base64
	} from '@/components/base64.js';
	export default {
		data() {
			return {
				shop: [],
				user: [],
				serve: [],
				endTime: '',
				txt: '未认证',
				shakeState: 0,
			};
		},
		onShow() {
			this.shakeState = 0
			// if(process.env.NODE_ENV === 'development'){
			// 	uni.setStorageSync('token', '9a2075ff711b402aa49280574176bafa');
			//     // console.log('开发环境')
			// }else{
			//     console.log('生产环境')
			// }
		
			this.init();
		},
		onNavigationBarButtonTap(e) {
			if (this.shakeState == 0) {
				this.shakeState = 1
				uni.navigateTo({
					url: '../more/more'
				});
			}
		},
		methods: {
			GoHelp() {
				uni.navigateTo({
					url: '../help/help'
				})
			},
			GoOpenVip() {
				if (this.shakeState == 0) {
					this.shakeState = 1
					uni.navigateTo({
						url: '../openServe/openServe'
					});
				}
			},
			async init() {
				// 个人信息
				let data = await myInfo();
				this.user = data.user;
				let serves = await storeinfo(); // 判断  商家服务
				if (serves.data != null) {
					let dataServe = serves.data;
					this.serve = dataServe;
					if (dataServe.status == 0) {
						this.txt = '审核中';
					} else if (dataServe.status == 1) {
						this.txt = '已认证';
						let endTime = await getEndDate(); //获取 过期时间
						this.endTime = endTime.endDate.substring(0, 10);
					} else if (dataServe.status == 2) {
						this.txt = '失败';
					}
				}
			},
			checkingCoupon() {
				uni.scanCode({
					success: res => {
						let codess = Base64.decode(res.result);
						codess = codess.substr(8);
						codess = String(codess);
						let data = {
							id: codess
						};
						if (codess == null) {
							uni.showToast({
								title: '请重新扫码',
								icon: 'none'
							})
						} else if (res.result.length < 20) {
							uni.showToast({
								title: '请重新扫码',
								icon: 'none'
							})
						} else {
							useCoupon(data).then(ress => {
								let parameter = {
									code: ress.code,
									msg: ress.msg,
								};
								uni.setStorageSync('payData', parameter);
								uni.navigateTo({
									url: '../couponChecking/couponChecking'
								});
							});
						}
					}
				});
			},
			Go(e) {
				let url = '';
				switch (e) {
					case 0: //商家认证
						if (this.serve == '') {
							url = '../shopNews/shopNews';
						} else if (this.serve.status == 0) {
							url = '../wait/wait?state=0';
						} else if (this.serve.status == 1) {
							uni.setStorageSync('shopNews', this.serve);
							url = '../shopSet/shopSet';
						} else if (this.serve.status == 2) {
							url = '../wait/wait?state=2&txt=' + this.serve.opinion;
						}
						break;
					case 1: //开办会员卡
						url = '../openVip/openVip';
						break;
					case 2: //充值会员卡
						url = '../recharge/recharge';
						break;
					case 3: //会员卡收款
						url = '../vipPay/vipPay';
						break;
					case 4: //菊豆收款
						url = '../judouPay/judouPay';
						break;
					case 5: //我的会员
						url = '../member/member';
						break;
					case 6: //营销管理
						url = '../couponList/couponList?name=' + this.serve.name;
						break;
					case 7: //优惠券折扣
						if (this.serve.status == 1) {
							this.checkingCoupon();
						} else {
							uni.showToast({
								title: '请先认证商家',
								icon: 'none'
							});
						}
						break;
					case 8: //公共管理
						url = '../publicNews/publicNews'
						break;
				}
				if (this.serve.status == 1) {
					uni.navigateTo({
						url: url
					});
				} else {
					if (e == 0) {
						if(this.shakeState == 0){
							this.shakeState = 1
							uni.navigateTo({
								url: url
							});		
						} 
					} else {
						uni.showToast({
							title: '请先认证商家',
							icon: 'none'
						});
					}
				}
			}
		}
	};
</script>

<style lang="less" scoped>
	@import './index.less';
</style>
